package Classes.GameViews.ViewPanels// ActionScript file
{
	import Classes.GameDatas.GD_AllFriends;
	import Classes.GameDatas.GD_BuildingItem;
	import Classes.GameDatas.GD_Building_Func;
	import Classes.GameDatas.GD_Mission;
	import Classes.GameDatas.GD_Player;
	import Classes.GameDatas.GD_QQhz;
	import Classes.GameDatas.GD_Shop;
	import Classes.GameUtils.GU_Sound;
	import Classes.GameUtils.GU_dealPower;
	import Classes.GameUtils.GU_filters;
	import Classes.GameUtils.MyTipSprite;
	import Classes.GameUtils.ToolTip_Sprite;
	import Classes.GameViews.GV_Map;
	import Classes.Managers.M_Communication;
	import Classes.Managers.M_ConfigData;
	import Classes.staticinfo.Language;
	import Classes.staticinfo.StaticInfo;
	
	import UIComponents.IUseItem;
	
	import com.greensock.TweenLite;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.display.StageDisplayState;
	import flash.events.Event;
	import flash.events.FullScreenEvent;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.external.ExternalInterface;
	import flash.filters.ColorMatrixFilter;
	import flash.geom.Point;
	import flash.system.ApplicationDomain;
	import flash.text.TextField;
	import flash.utils.Timer;
	
	/**
	 *主界面类 
	 * @author 葛增文
	 * 
	 */	
	public class VP_Main extends ViewPanel
	{
		private static var _instance:VP_Main;
		private var _interfaceUI:Sprite;
		public var ljMc:MovieClip;
		public var ljLv:TextField;
		public var movementMc:MovieClip;
		public function VP_Main():void
		{
			this.init();
		}
		
		private function init():void
		{
			this._interfaceUI=new (ApplicationDomain.currentDomain.getDefinition("UIMain_v") as Class);
			this.ljMc=this._interfaceUI["lianJiMC"] as MovieClip;
			this.ljLv=this._interfaceUI["litf"] as TextField;
			this.ljMc.visible=this.ljLv.visible=false;
			this.movementMc	=	this._interfaceUI.getChildByName("movement") as MovieClip;
			this.movementMc.gotoAndStop(1);
			//			this.movementMc.visible=false;
			this.movementMc.buttonMode=true;
			
			this.addChild(this.interfaceUI);
			
			
			this.addListener();
			
			this.addObserveFuncs();
			this.ljMc.addEventListener(Event.ENTER_FRAME,enter);
			this.movementMc.addEventListener(MouseEvent.CLICK,function(e:Event):void{
				VP_movement.instance.openPanel();
			});
			
			this.newMessage	= 0;
		}
		
		public function setMaxVisableFriendNum(maxcount:int):void
		{
			//每天最多拜访有奖的好友数
			this.interfaceUI["panelMain"]["maxVisitleNum"]=maxcount;
		}
		
		private function addListener():void
		{
			this.addEventListener("openImgPanel",openImgPanelHandler);
			this.addEventListener("openPackagePanel",openPackagePanelHandler);
			this.addEventListener("openShopPanel",openShopPanelHandler);
			this.addEventListener("openBuildingPanel",openBuildingPanelHandler);
			this.addEventListener("finishBuild",finishBuildHandler);
			this.addEventListener("changeToMoveMode",changeToMoveModeHandler);
			this.addEventListener("changeToCleanMode",changeToCleanModeHandler);
			this.addEventListener("recoverBuild",recoverBuildHandler);
			this.addEventListener("changeUserWeapon",changeUserWeapon);
			this.addEventListener("goHomeEvent",gohomeFun);
			this.addEventListener("openExChange",openExChangeHandler);			//打开兑换面板
			
			
			this.addEventListener("PB_mouseOVER",changeCursorOverHandler);		//鼠标移动到建筑面板
			this.addEventListener("PB_mouseOUT",changeCursorOutHandler);		   	//鼠标移出到建筑面板
			this.addEventListener("PB_mouseDOWN",changeCursorDownHandler);		//鼠标点击到建筑面板
			this.addEventListener("isClickItem",clickGVMapBuildFun);		//有点击到建筑面板中的项
			this.addEventListener("PB_sureDOWN",sureDownHandler);		//鼠标按下，确认按扭
			
			//黄钻
			this.addEventListener("openNewqqVip",openNewqqVip);	
			this.addEventListener("openDayqqVip",openDayqqVip);	
			this.addEventListener("openDayqqVipLater",openDayqqVip);	
			
			//声效全屏这一块  功能
			this.addEventListener("BgMusic",controlBgMusicFun);	
			this.addEventListener("CommMusic",controlCommMusicFun);
			this.addEventListener("fullScreenClick",controlFullFun);
			
			this.addEventListener("sevenFun",sevenFun);	
			this.addEventListener("dongtaiFun",dongtaiFun);
			
			//消息系统
			this.addEventListener("messageClick",clickMessageHD);
//			ToolTip_Sprite.getInstance().setTip( _interfaceUI["MessageNew"] as DisplayObject, new MyTipSprite("My phone:接收和储存消息的电话"));
			ToolTip_Sprite.getInstance().setTip( _interfaceUI["Message"] as DisplayObject, new MyTipSprite(Language.messageHotTip));
			
			//知道箭头
			this.addEventListener("addarrowtobuilid",addArrowBuild);
			this.addEventListener("addarrowtock",addArrowCK);
			this.addEventListener("addarrowtozs",addArrowZS);
			this.addEventListener("addarrow",addarrowToUpOrDown);
			this.addEventListener("notnewguidesd",notnewguidesd);
			this.addEventListener("friendrollover",friendrollover);
			this.addEventListener("friendrollout",friendrollout);
			
			
			//建筑面板重绘
			this.addEventListener("buildReShow",buildReShowHandler);
			
			//上下拉好友，建筑面板
			this.addEventListener("clickCLSmall", clickCL);//clickCLSmallHandler);
			this.addEventListener("clickCLBig", clickCL);//clickCLBigHandler);
			
			//邀请好友
			this.addEventListener("yqhy", yqhyFun);
			
			//开服活动
			this.movementMc.addEventListener(MouseEvent.ROLL_OVER,playMc);
			this.movementMc.addEventListener(MouseEvent.ROLL_OUT,stopMc);
		}
		
		/**
		 * 播放开服活动 
		 * @param e
		 */		
		private function playMc(e:MouseEvent):void
		{
			this.movementMc.play();
		}
		/**
		 * 停止开服活动 
		 * @param e
		 * 
		 */		
		private function stopMc(e:MouseEvent):void
		{
			this.movementMc.gotoAndStop(1);
		}
		
		/**
		 *设置是否已建造 
		 * @param e
		 * 
		 */
		public function buildReShowHandler(e:Event):void{
			var ary:Array=new Array;
			
			if(GV_Map.instance.mapData==null)return;
			
			for each(var gdb:GD_Building_Func	in GV_Map.instance.mapData.buildingsObj)
			{
				if(! (gdb.tmpHasBuildInMap))
					ary.push(gdb.buildingType);
			}
			interfaceUI["panelBuild"]["setHaveOne"](ary);
		}
		
		
		/**
		 * 设置是否已建造，等一段时间后再设置，
		 * 
		 */
		public function buildIsHaveOne():void{
			//判断是否“已建造”
			if( GV_Map.instance.buildMode != GV_Map.CANNOTBUILDMODE){	
				var timer:Timer=new Timer(500,1);
				timer.addEventListener(TimerEvent.TIMER,function(e:Event):void{
					buildReShowHandler(null);
				});
				timer.start();
			}
		}
		
		
		public function addArrowBuild(e:Event):void
		{
			GU_dealPower.instance.buyJTBuild();
		}
		public function addArrowCK(e:Event):void
		{
			GU_dealPower.instance.removeBuildArrow();
		}
		public function addArrowZS(e:Event):void
		{
			GU_dealPower.instance.removeBuildArrow();
		}
		
		public function addarrowToUpOrDown(e:Event):void
		{
			GU_dealPower.instance.clickJTWeapon();
		}
		
		public function notnewguidesd(e:Event):void
		{
			VP_errorPanel.instance.setErrorMessage(Language.noOperatePower);
			VP_errorPanel.instance.enterFrame();
		}
		
		public function  friendrollover(e:Event):void
		{
			GU_dealPower.instance.clickFriendBtn();
		}
		
		public function  friendrollout(e:Event):void
		{
			GU_dealPower.instance.clickFriendFrame();
		}
		
		public function clickMessageHD(e:Event):void
		{
			var dis:DisplayObject	=	interfaceUI["Message"] as DisplayObject;
			var globalpt:Point	=	dis.localToGlobal(new Point(0,0));
			VP_message.instance.backObject	=	{x:globalpt.x,y:globalpt.y,scaleX:0.1,scaleY:0.1};
			VP_message.instance.openPanel();
		}
		
		private function clickGVMapBuildFun(e:Event):void
		{
			GV_Map.instance.isClickItem(e);
		}
		
		/**
		 * 打开七日礼包页面 
		 * @param e
		 */		
		private function sevenFun(e:Event):void
		{
			VP_SevenDaysRewardUI.instance.open();
		}
		
		/**
		 * 领取在线礼包 
		 * @param e
		 */		
		private function dongtaiFun(e:Event):void
		{
			M_Communication.instance.send(127013);
		}
		
		private function addObserveFuncs():void
		{
			this.addObserveFunc(GD_Player.instance,"playerLv",showPlayerLv);
			this.addObserveFunc(GD_Player.instance,"money",showMyJB);
			this.addObserveFunc(GD_Player.instance,"gold",showMyOB);
			this.addObserveFunc(GD_Player.instance,"exp",showExp);
			this.addObserveFunc(GD_Player.instance,"actPoint",showActPoint);
			this.addObserveFunc(GD_Player.instance,"friendAct",showFriendAct);
			this.addObserveFunc(GD_Player.instance,"missions",showMissions);
			this.addObserveFunc(GD_Player.instance,"storeBuildingItems",showStoreBuildingItems);
			this.addObserveFunc(GD_Shop.instance,"shopDecorationItems",showShopDecorationItems);
			this.addObserveFunc(GD_Shop.instance,"shopBuildingItems",showShopBuildingItems);
			this.addObserveFunc(GD_Player.instance,"powerTimer",showTimer);
			this.addObserveFunc(GD_AllFriends.instance,"friendList",showFriend);
			this.addObserveFunc(GD_Player.instance,"fivePowerTimer",operateTime,false);
			this.addObserveFunc(GD_Player.instance,"quickCloseTimerLister",completeTimeOperate,false);
			this.addObserveFunc(GD_Player.instance,"addWeaponToEquipmentArea",setQhWqData,true);
			this.addObserveFunc(GD_Player.instance,"isInHome",controlerActPanel);
			this.addObserveFunc(GD_Player.instance,"QQVip",controlQQVip);
			this.addObserveFunc(GD_Player.instance,"exItemNum",updataExchangeBuildItemNum);
			this.addObserveFunc(GD_Player.instance,"onLineGift",hanldOnLineGift);
		}
		
		private function updataExchangeBuildItemNum():void
		{
			this.interfaceUI["updataExchangeBuildItemNum"](GD_Player.instance.exchangeBuildItemNum);
		}
		
		public function keyFun(e:KeyboardEvent):void
		{
			this.interfaceUI["keyFun"](e);
		}
		
		/**
		 * 处理连击 
		 * @param isVisable 连击按钮是否显示
		 * @param jumpFrame 调到第几帧
		 * @param lv  当前连击次数
		 */		
		private var callBackFun:Function;
		public function  hanldLianJIFun(isVisable:Boolean=true,jumpFrame:Number=1,lv:Number=1,callFun:Function=null):void
		{
			this.ljMc.visible=isVisable;
			this.callBackFun=callFun;
			if(isVisable)
			{
				if(jumpFrame>=100)
				{
					this.ljLv.visible=true;
					this.ljLv.text=String(lv);
					this.ljMc.gotoAndPlay(100);
				}else{
					this.ljLv.visible=false;
					this.ljMc.gotoAndStop(jumpFrame);
				}
			}
		}
		
		/**
		 * 控制行动力面板的显示 
		 */		
		public function controlerActPanel():void
		{
			var isInHome:Boolean=GD_Player.instance.character.characterState==2?false:true;
			this.interfaceUI["controlerActPanel"](isInHome);
			//控制倒计时面板跟建筑按钮
			this.interfaceUI["setBuildBtnVisabel"](isInHome);
			if(isInHome)
			{
				(this.interfaceUI["showTimerContainer"] as DisplayObject).visible=GD_Player.instance.actPoint<GD_Player.instance.playCurrentMaxActPoint?true:false;
			}else{
				(this.interfaceUI["showTimerContainer"] as DisplayObject).visible=false;
			}
		}
		
		
		public function setPlayEle1(dis:DisplayObject=null):void
		{
			this.interfaceUI["setPlayEle1"](dis,Language.haveSpeedTips);
		}
		
		public function setPlayerEle2(dis:DisplayObject=null):void
		{
			
			this.interfaceUI["setPlayerEle2"](dis);
		}
		
		public function setPlayerEle3(dis:DisplayObject=null):void
		{
			
			this.interfaceUI["setPlayEle3"](dis,Language.everyDayLifeTips);
		}
		
		public function getPlayerEle2Tips():DisplayObject
		{
			return this.interfaceUI["PlayerEle2Tips"];
		}
		
		
		private function enter(ev:Event):void
		{
			if(null!=callBackFun && this.ljMc.currentFrame==this.ljMc.totalFrames)
			{
				//				this.ljMc.removeEventListener(Event.ENTER_FRAME,enter);
				callBackFun();
			}
		}
		
		private function showPlayerLv():void
		{
			this.interfaceUI["showPlayerLv"](GD_Player.instance.playerLv);
			
			
			showShopBuildingItems();
			showShopDecorationItems();
			
			//			(this.interfaceUI as UIMain).panelBuild.reshow();
			
		}
		
		private function showMyJB():void
		{
			this.interfaceUI["showMyJB"](GD_Player.instance.money);
		}
		
		private function showMyOB():void
		{
			this.interfaceUI["showMyOB"](GD_Player.instance.gold);
		}
		
		private function showExp():void
		{
			this.interfaceUI["showExp"](GD_Player.instance.playerExp,GD_Player.instance.playerCurrentMaxExp);
		}
		
		private function showActPoint():void
		{
			this.interfaceUI["showActPoint"](GD_Player.instance.actPoint,GD_Player.instance.playCurrentMaxActPoint);
		}
		
		private function showFriendAct():void
		{
			this.interfaceUI["showFriendAct"](GD_Player.instance.friendAct,5);
		}
		
		private function setQhWqData():void
		{
			for each(var it:IUseItem in GD_Player.instance.selectWeapons)
			this.interfaceUI["setQhWqData"](GD_Player.instance.selectWeapons);
		}
		
		/**
		 * 控制七日礼包的显示 
		 * @param isvisable
		 */	
		public function controlSevenBtn(isvisable:Boolean):void
		{
			this.interfaceUI["controlSevenBtn"](isvisable);
		}
		
		/**
		 * 控制七日礼包停止摆动 
		 * @param isvisable
		 */		
		public function controlPlaySevenBtn():void
		{
			this.interfaceUI["controlPlaySevenBtn"]();
			
		}
		
		/**
		 * 控制动态礼包的显示 
		 * @param isvisable
		 */	
		public function controlDongtaiBtn(isvisable:Boolean):void
		{
			this.interfaceUI["controlDongtaiBtn"](isvisable);
		}
		
		/**
		 * 控制动态礼包时间倒计时 
		 * @param value
		 */		
		public function setDongtaiTimer(value:String):void
		{
			this.interfaceUI["setDongtaiTimer"](value);
		}
		
		private var onLineGiftTimer:Timer;
		private var totalSecMins:Number;
		private function hanldOnLineGift():void
		{
			this.interfaceUI["controlDongTaiLqBtn"](false,StaticInfo.getSmallDarker());
			var onLineTimer:int=GD_Player.instance.onlineMinute;
			if(onLineTimer<=0)
			{
				this.controlDongtaiBtn(false);
			}else{
				var totalCount:int=onLineTimer*60;
				this.totalSecMins=totalCount*1000;
				onLineGiftTimer=new Timer(1000,totalCount);
				onLineGiftTimer.addEventListener(TimerEvent.TIMER,onLineTimerHalder);
				onLineGiftTimer.addEventListener(TimerEvent.TIMER_COMPLETE,onLineCompleteTimerHalder);
				onLineGiftTimer.start();
				this.controlDongtaiBtn(true);
			}
		}
		
		private function onLineTimerHalder(evt:TimerEvent):void
		{
			var data:Date=new Date(null,null,null,null,null,null,totalSecMins);
			var tmpSecond:String=data.seconds<10?("0"+data.seconds):String(data.seconds);
			var str:String=data.minutes+":"+tmpSecond;
			this.setDongtaiTimer(str);
			totalSecMins-=1000;
		}
		
		private function onLineCompleteTimerHalder(evt:TimerEvent):void
		{
			this.interfaceUI["controlDongTaiLqBtn"](true,null);
			this.setDongtaiTimer("0:0");
			if(null==onLineGiftTimer)return;
			onLineGiftTimer.removeEventListener(TimerEvent.TIMER,onLineTimerHalder);
			onLineGiftTimer.removeEventListener(TimerEvent.TIMER_COMPLETE,onLineCompleteTimerHalder);
			onLineGiftTimer=null;
			this.totalSecMins=0;
			
		}
		
		/**
		 * 行动力恢复 
		 */		
		private function showTimer():void
		{
			if(GD_Player.instance.powerTime<1)
			{
				hideTimerTxt();
				GD_Player.instance.closeTimerLister=true;
			}else{
				operateTime(GD_Player.instance.powerTime);
			}
		}
		private var timer:Timer;
		private var _lastTimer:Number; 
		private function operateTime(lastTime:Number=300):void
		{
			GD_Player.instance.closeTimerLister=false;
			hideTimerTxt(true);
			_lastTimer=lastTime*1000;
			timer=new Timer(1000,lastTime);
			timer.addEventListener(TimerEvent.TIMER,timerHalder);
			timer.addEventListener(TimerEvent.TIMER_COMPLETE,completeTimerHalder);
			timer.start();
		}
		
		private function timerHalder(evt:TimerEvent):void
		{
			var data:Date=new Date(null,null,null,null,null,null,_lastTimer);
			var tmpSecond:String=data.seconds<10?("0"+data.seconds):String(data.seconds);
			var str:String=data.minutes+":"+tmpSecond;
			this.interfaceUI["showTimes"](str);
			_lastTimer-=1000;
		}
		
		private function completeTimerHalder(evt:TimerEvent):void
		{
			completeTimeOperate();
		}
		
		public function completeTimeOperate():void
		{
			if(null==timer)return;
			timer.removeEventListener(TimerEvent.TIMER,timerHalder);
			timer.removeEventListener(TimerEvent.TIMER_COMPLETE,completeTimerHalder);
			timer=null;
			if(GD_Player.playerNowAction<GD_Player.instance.playCurrentMaxActPoint)
			{
				GD_Player.playerNowAction+=1;
				GD_Player.instance.actPoint+=1;
				if(GD_Player.playerNowAction>=GD_Player.instance.playCurrentMaxActPoint)
				{
					GD_Player.instance.closeTimerLister=true;
					hideTimerTxt(false);
				}else{
					operateTime();
				}
			}
			if(GD_Player.playerNowAction>=GD_Player.instance.playCurrentMaxActPoint)
			{
				GD_Player.instance.closeTimerLister=true;
				hideTimerTxt(false);
			}
		}
		
		private function hideTimerTxt(_vilable:Boolean=false):void
		{
			if(GD_Player.instance.character.characterState==2)
			{
				(this.interfaceUI["showTimerContainer"] as DisplayObject).visible=false;
			}else{
				(this.interfaceUI["showTimerContainer"] as DisplayObject).visible=_vilable;
			}
		}
		
		private function showTownName():void
		{
			
		}
		
		private var orderInitMisFlag:Boolean=true;
		private function showMissions():void
		{
			var missionsAry:Array=new Array;
			
			if(orderInitMisFlag)
			{
				missionsAry=this.orderInitMission();
				this.orderInitMisFlag=false;
			}else{
				for each(var mission:GD_Mission in GD_Player.instance.missions)
				{
					if(mission.taskStyle!=10)//10为系统任务
					{
						missionsAry.push(mission);
					}
				}
			}
			this.interfaceUI["setMissionsAry"](missionsAry);
		}
		
		/**
		 * 在初始化的任务时进行排序 
		 */		
		private function orderInitMission():Array
		{
			var overMisArr:Array=new Array();
			var newMisArr:Array=new Array();
			var commMisArr:Array=new Array();
			
			for each(var mission:GD_Mission in GD_Player.instance.missions)
			{
				if(mission.missionStatue==1 && mission.checkMissionIsOver() && mission.taskStyle!=10)
				{
					overMisArr.push(mission);
				}else if(mission.missionStatue==0 && mission.taskStyle!=10)
				{
					newMisArr.push(mission);
				}else{
					if(mission.taskStyle!=10)
					{
						commMisArr.push(mission);
					}
				}
			}
			
			var tmpArr:Array=overMisArr.concat(newMisArr,commMisArr);
			return tmpArr;
		}
		
		private function showStoreBuildingItems():void
		{
			var buildingItemsAry:Array=new Array;
			for each(var buildingItem:GD_BuildingItem in GD_Player.instance.storeBuildings)
			{
				if(buildingItem.buildingItemNum)
				{
					buildingItemsAry.push(buildingItem);
				}
			}
			buildingItemsAry.sortOn("buildingItemType",Array.NUMERIC);
			this.interfaceUI["setStorageBuildingsAry"](buildingItemsAry);
		}
		
		private function showShopDecorationItems():void
		{
			var decorationItemsAry:Array=GD_Shop.instance.decorationItemsAry;
			this.interfaceUI["setShopDecorationsAry"](decorationItemsAry);
		}
		
		private function showShopBuildingItems():void
		{
			var buildingItemsAry:Array=GD_Shop.instance.buildingItemsAry;
			this.interfaceUI["setShopBuildingsAry"](buildingItemsAry);
		}
		
		private function showFriend():void
		{
			this.interfaceUI["setFriendData"](GD_AllFriends.instance.AllFriendsArr);
		}
		
		private function openImgPanelHandler(e:Event):void
		{
			//(GV_Map.instance.controlTarget as MMT_Character).turnToZombie();
		}
		
		private function gohomeFun(e:Event):void
		{
			VP_OpenWinView.instance.openGotoFriendPanel();
			GD_Player.instance.sendGoHomeComm();
		}
		
		private function openExChangeHandler(e:Event):void
		{
			var dis:DisplayObject	=	this.interfaceUI.getChildByName("btn_myJB") as DisplayObject;
			var globalpt:Point	=	dis.localToGlobal(new Point(0,0));
			VP_exChangePanel.instance.backObject	=  {x:globalpt.x,y:globalpt.y,scaleX:0.1,scaleY:0.1};
			VP_exChangePanel.instance.openPanel();
		}
		private function openPackagePanelHandler(e:Event):void
		{
			var dis:DisplayObject	=	this.interfaceUI["panelMain"].getChildByName("button_package") as DisplayObject;
			var globalpt:Point	=	dis.localToGlobal(new Point(0,0));
			VP_Package.instance.backObject	=	{x:globalpt.x,y:globalpt.y,scaleX:0.1,scaleY:0.1};
			GU_dealPower.instance.clickCollectBtn();
			VP_Package.instance.openAt(this.showScene);
		}
		
		private function openShopPanelHandler(e:Event):void
		{
			//整个游戏的权限由自己控制   10000213系统权限---点击商城
			if(null==GD_Player.instance.playPowerObj[10000213] || 0==GD_Player.instance.playPowerObj[10000213])
			{
				VP_errorPanel.instance.noPowerMsg();
				return;
			}
			
			var dis:DisplayObject	=	this.interfaceUI["panelMain"].getChildByName("button_shop") as DisplayObject;
			var globalpt:Point	=	dis.localToGlobal(new Point(0,0));
			VP_StorePanel.instance.backObject	=  {x:globalpt.x,y:globalpt.y,scaleX:0.1,scaleY:0.1};
			GU_dealPower.instance.newGuideshop();
			GU_dealPower.instance.clickBuyWeapon();
			VP_StorePanel.instance.openAt(this.showScene);
		}
		
		private function openBuildingPanelHandler(e:Event):void
		{
			
			//整个游戏的权限由自己控制   10000206系统权限---点击建筑
			if(null==GD_Player.instance.playPowerObj[10000206] || 0==GD_Player.instance.playPowerObj[10000206])
			{
				VP_errorPanel.instance.noPowerMsg();
				return;
			}
			this.isHideMainPanel	=	false;
			this._interfaceUI["showBuildPanel"]();
			GV_Map.instance.beginBuild();
			GU_dealPower.instance.buyBuildstep();
			
		}
		
		private function finishBuildHandler(e:Event):void
		{
			this.isHideMainPanel	=	false;
			this._interfaceUI["showMainPanel"]();
			GU_dealPower.instance.removeBuildArrow();
			GV_Map.instance.finishBuild();
		}
		
		private function changeToMoveModeHandler(e:Event):void
		{
			GV_Map.instance.changeBuildMode(GV_Map.MOVEMODE);
		}
		
		private function changeToCleanModeHandler(e:Event):void
		{
			GV_Map.instance.changeBuildMode(GV_Map.CLEANMODE);
		}
		
		private function recoverBuildHandler(e:Event):void
		{
			GV_Map.instance.recoverBuild();
		}
		
		private function changeUserWeapon(e:Event):void
		{
			GD_Player.instance.currentWeapon=this.interfaceUI["currentWeaponId"];
		}
		
		/*getter & setter*/
		public static function get instance():VP_Main
		{
			if(!_instance)_instance=new VP_Main;
			return _instance;
		}
		
		public function get interfaceUI():Sprite
		{
			return _interfaceUI;
		}
		
		/**
		 *鼠标移动到建筑面板 
		 * @param e
		 * 
		 */
		private function changeCursorOverHandler(e:Event):void
		{
			GV_Map.instance.changeCursor("over");
		}
		/**
		 *鼠标移出到建筑面板 
		 * @param e
		 * 
		 */
		private function changeCursorOutHandler(e:Event):void
		{
			GV_Map.instance.changeCursor("out");
			
		}
		/**
		 *鼠标点击到建筑面板 
		 * @param e
		 * 
		 */
		private function changeCursorDownHandler(e:Event):void
		{
			GV_Map.instance.changeCursor("down");
			
		}
		
		/**
		 *鼠标按下到建筑面板确认按扭 
		 * @param e
		 * 
		 */
		private function sureDownHandler(e:Event):void
		{
			GV_Map.instance.finishBuildDown(e);
		}
		
		private function controlQQVip():void
		{
			if(M_ConfigData.instance.isOpenHz)
			{
				if(GD_Player.instance.qqVipId==0 || GD_Player.instance.isGetNewqqGift==1)
				{
					controlBtnVisable(true);
				}else{
					if(GD_Player.instance.isGetDayqqGift==1)
					{
						controlBtnVisable(false,true,false);
					}else{
						controlBtnVisable(false,false,true);
					}
				}
			}else{
				controlBtnVisable();
			}
			controlMoenyIcon();
		}
		
		/**
		 * 控制VIP的显示 
		 * @param newVip
		 * @param dayVip
		 * @param openVip
		 */	
		public function controlBtnVisable(newVip:Boolean=false,dayVip:Boolean=false,openVip:Boolean=false):void
		{
			this._interfaceUI["controlBtnVisable"](newVip,dayVip,openVip);
		}
		
		public function controlMoenyIcon():void
		{
			this._interfaceUI["controlMoenyIcon"](M_ConfigData.instance.isOpenQQVip);
		}
		
		private function openNewqqVip(e:Event):void
		{
			GD_QQhz.instance.openNewqqVip();
		}
		
		private function openDayqqVip(e:Event):void
		{
			GD_QQhz.instance.openDayqqVip();
		}
		
		
		//****************************************************************   系统条 ***********************************
		private var grayfilter:ColorMatrixFilter = GU_filters.grayfilter ;
		/**
		 * 控制 背景音乐 
		 * @param e
		 */		
		private function controlBgMusicFun(e:Event):void
		{
			GU_Sound.instance.puaseOrPlayBgSound();
			
			//关闭热感
			var target:DisplayObject = e.currentTarget as DisplayObject;
			var container:DisplayObjectContainer = target.stage as DisplayObjectContainer;
			if(container == null) return;
			var tip:DisplayObject = container.getChildByName("tip");
			if(tip)	container.removeChild(tip);
			
			if(GU_Sound.instance.playBgFlag){
				ToolTip_Sprite.getInstance().setTipTxt(Language.offBgMusic,(_interfaceUI["doanmb"] as Sprite).getChildByName("bgMusicBtn"),true);
				(_interfaceUI["doanmb"] as Sprite).getChildByName("bgMusicBtn").filters	=	null;
			}
			else{
				ToolTip_Sprite.getInstance().setTipTxt(Language.onBgMusic,(_interfaceUI["doanmb"] as Sprite).getChildByName("bgMusicBtn"),true);
				(_interfaceUI["doanmb"] as Sprite).getChildByName("bgMusicBtn").filters	=	StaticInfo.DARKER_DISABLE_FILTER;
			}
			
		}
		/**
		 * 控制音效 
		 * @param e
		 */		
		private function controlCommMusicFun(e:Event):void
		{
			GU_Sound.instance.stopOrPlayCommSound();
			
			//关闭热感
			var target:DisplayObject = e.currentTarget as DisplayObject;
			var container:DisplayObjectContainer = target.stage as DisplayObjectContainer;
			if(container == null) return;
			var tip:DisplayObject = container.getChildByName("tip");
			if(tip)	container.removeChild(tip);
			
			if(GU_Sound.instance.playCommFlag){
				ToolTip_Sprite.getInstance().setTipTxt(Language.offCommMusic,(_interfaceUI["doanmb"] as Sprite).getChildByName("commMusicBtn"),true);
				(_interfaceUI["doanmb"] as Sprite).getChildByName("commMusicBtn").filters	=	null;
			}
			else{
				ToolTip_Sprite.getInstance().setTipTxt(Language.onCommMusic,(_interfaceUI["doanmb"] as Sprite).getChildByName("commMusicBtn"),true);
				(_interfaceUI["doanmb"] as Sprite).getChildByName("commMusicBtn").filters	=	StaticInfo.DARKER_DISABLE_FILTER;
			}
		}
		
		private var isAddl:Boolean=false;
		/**
		 * 控制全屏 
		 * @param e
		 */		
		private function controlFullFun(e:Event):void
		{
			if(!this.stage.hasEventListener(FullScreenEvent.FULL_SCREEN)){
				this.stage.addEventListener(FullScreenEvent.FULL_SCREEN,upDatePosition);
			}
			if(!_interfaceUI["isFullScreen"]){
				stage.displayState = StageDisplayState.FULL_SCREEN;
				(_interfaceUI["doanmb"] as Sprite).getChildByName("fullScreenBtn").filters	=	StaticInfo.DARKER_DISABLE_FILTER;
				//全屏  时  把模式变为 transparent
				M_ConfigData.instance.changeParams("transparent");
			}
			else{
				stage.displayState = StageDisplayState.NORMAL;
				
				(_interfaceUI["doanmb"] as Sprite).getChildByName("fullScreenBtn").filters	=	null;
				
				//不是全屏是 模式变为 window
				M_ConfigData.instance.changeParams("window");
				//this._interfaceUI["isFullScreen"]=false;
			}
			
			//			trace(GV_Map.instance.x,GV_Map.instance.y,GV_Map.instance.width,GV_Map.instance.height);
			
			//			trace(GV_Map.instance.width+GV_Map.instance.x-stage.stageWidth/2,stage.stageWidth);
			
			var disx:Number		=	(GV_Map.instance.width/2+GV_Map.instance.x)	-	stage.stageWidth;
			var disy:Number		=	(GV_Map.instance.height+GV_Map.instance.y)	-	stage.stageHeight;
			if( disy<0) GV_Map.instance.y -= disy;
			if( disx<0) GV_Map.instance.x -= disx;
			
			upDatePosition();
			
		}
		
		/**
		 *更新各面板位置。（主要针对全屏） 
		 * 
		 */
		public function upDatePosition(e:Event=null):void
		{
			//			GV_Map.instance.buildMode	=	GV_Map.CANNOTBUILDMODE;
			if(this.parent.stage.displayState==StageDisplayState.FULL_SCREEN)
			{
				(_interfaceUI["doanmb"] as Sprite).getChildByName("fullScreenBtn").filters	=	StaticInfo.DARKER_DISABLE_FILTER;
			}else{
				(_interfaceUI["doanmb"] as Sprite).getChildByName("fullScreenBtn").filters	=	null;
			}
			//主面板，建筑面板位置
			var pb_offsetY:Number=-200;
			//			var pb_offsetX:Number=-50;
			var pb_offsetX:Number=-80;
			
			var mb_offsetX:Number=-	40;
			var mb_offsetY:Number=8;
			
			//齿轮
			var cl_offsetX:Number=-40;
			var cl_offsetY:Number=-60;
			
			this._interfaceUI["panelBuild"].x		=	(this.parent.stage.stageWidth-this._interfaceUI["panelBuild"]["width"])/2+pb_offsetX;
			this._interfaceUI["panelMain"].x		=	(this.parent.stage.stageWidth-this._interfaceUI["panelMain"]["width"])/2+mb_offsetX;
			
			
			
			
			if(this._isHideMainPanel)
			{
				this._interfaceUI["panelBuild"].y		=	this.parent.stage.stageHeight+this._panelBuildOffsetY;
				this._interfaceUI["panelMain"].y		=	this.parent.stage.stageHeight+this._panelMainOffsetY;//(this.parent.stage.stageHeight-this._interfaceUI["panelMain"]["height"]/2)+mb_offsetY;
				
			}
			else
			{
				this._interfaceUI["panelBuild"].y		=	this.parent.stage.stageHeight;//(this.parent.stage.stageHeight+pb_offsetY);
				this._interfaceUI["panelMain"].y		=	this.parent.stage.stageHeight;//(this.parent.stage.stageHeight-this._interfaceUI["panelMain"]["height"]/2)+mb_offsetY;
				
			}
			
			this._interfaceUI["panelBuildInitY"]	=	this._interfaceUI["panelBuild"].y;
			this._interfaceUI["panelMainInitY"]	=	this._interfaceUI["panelMain"].y;
			
			this._interfaceUI["BPdefaultY"]	=	this.parent.stage.stageHeight+this._interfaceUI["panelBuild"].height;
			this._interfaceUI["MPdefaultY"]	=	this.parent.stage.stageHeight+this._interfaceUI["panelMain"].height/2;
			
			
//			if(GV_Map.instance.buildMode==GV_Map.CANNOTBUILDMODE)
			if(!VP_Main.instance.interfaceUI["isBuildMode"])
				this._interfaceUI["panelBuild"].y	=	this._interfaceUI["BPdefaultY"];
			else
				this._interfaceUI["panelMain"].y	=	this._interfaceUI["MPdefaultY"];
			
			
			this._interfaceUI["lianJiMC"].x	=	this.parent.stage.stageWidth/2;
			
			this._interfaceUI.getChildByName("bar_system").x 			=	this.parent.stage.stageWidth-this._interfaceUI.getChildByName("bar_system").width;
			this._interfaceUI.getChildByName("sevenGiftBtn").x 		=	this.parent.stage.stageWidth-this._interfaceUI.getChildByName("sevenGiftBtn").width/2;
			this._interfaceUI.getChildByName("dongtaiGiftBtn").x 		=	this.parent.stage.stageWidth-this._interfaceUI.getChildByName("dongtaiGiftBtn").width/2;
			//金币务，o币条位置
			
			VP_getItems.instance.upDatePosition();
			
			this.interfaceUI["hideSlideFastenerBtn"]["targetUI"].x		=	cl_offsetX + this._interfaceUI["panelBuild"].x+this._interfaceUI["panelBuild"].width;
			this.interfaceUI["hideSlideFastenerBtn"]["targetUI"].y		=	cl_offsetY + this.parent.stage.stageHeight;
			
			GD_Player.instance.touchObserve("fullScreen");
			
			isHideMainPanel	=	false;
			
			//以后要发布一个事件  有父类来控制其位置
			//			VP_errorPanel.instance.updatePosition();
			VP_TextWinPanel.instance.updatePosition();
			VP_OpenWinView.instance.updatePosition();
			VP_Mission.instance.updatePosition();
			//			VP_Package.instance.updatePosition();
			VP_StorePanel.instance.updatePosition();
			VP_NPCDialog.instance.updatePosition();
			VP_QQTQView.instance.updatePosition();
			VP_FastBuy_actPoint.instance.updatePosition();
			VP_FastBuy_weapon.instance.updatePosition();
			VP_SevenDaysRewardUI.instance.updatePosition();
			VP_RewardItemWindon.instance.updatePosition();
			VP_movement.instance.updatePosition();
			
			this.movementMc.x	=	this.parent.stage.stageWidth-this.movementMc.width;
		}
		
		
		//********************************************************************  消息系统 **********************************8
		/**
		 *设置拥有的新消息数 
		 * @param count
		 * 
		 */
		public function set newMessage(count:uint):void
		{
			if(count==0){
				//				 ( (this._interfaceUI["message"] as Sprite).getChildByName("txtNewMessage") as TextField).visible	=	false;
				//				 ( (this._interfaceUI["message"] as Sprite).getChildByName("spHt") as TextField).visible	=	true;
				(this._interfaceUI["MessageNew"] as Sprite).visible		=	false;
				(this._interfaceUI["Message"] as Sprite).visible			=	true;
				(this._interfaceUI["txtMessageNewContainer"] as DisplayObjectContainer).visible	=	false;
				//				(this._interfaceUI["txtMessageNew"] as TextField).visible	=	false;
				
			}
			else{
				(this._interfaceUI["Message"] as Sprite).visible				=	false;
				(this._interfaceUI["MessageNew"] as MovieClip).visible		=	true;
				(this._interfaceUI["txtMessageNew"] as TextField).selectable=	false;
				//				(this._interfaceUI["txtMessageNew"] as TextField).visible	=	true;
				(this._interfaceUI["txtMessageNewContainer"] as DisplayObjectContainer).visible	=	true;
				(this._interfaceUI["txtMessageNew"] as TextField).text		=	count.toString();
				(this._interfaceUI["MessageNew"] as MovieClip).play();
				
				
				//				( (this._interfaceUI["message"] as Sprite).getChildByName("txtNewMessage") as TextField).visible	=	true;
				//				( (this._interfaceUI["message"] as Sprite).getChildByName("spHt") as TextField).visible	=	false;
				//				( (this._interfaceUI["message"] as Sprite).getChildByName("txtNewMessage") as TextField).text	=	count.toString();
			}
			
			
			
			//			(this.MessageNew.getChildByName("txMessageNew") as TextField ).selectable=false;
			//			(this.MessageNew.getChildByName("txMessageNew") as TextField ).mouseEnabled=false
			
		}
		
		
		
		private var _isHideMainPanel:Boolean=false;
		private var _oldMainY:Number;
		private var _oldBuildY:Number;
		private var _isMoveMainPanel:Boolean=false;
		private var _isMoveBuildPanel:Boolean=false;
		private var _panelMainOffsetY:Number=110;
		private var _panelBuildOffsetY:Number=120;
		/**
		 *设置隐藏vpMain 
		 * @param value
		 * 
		 */
		public function set isHideMainPanel(value:Boolean):void
		{
			//			trace("key",this._isMoveMainPanel,this._isMoveBuildPanel,value,this.interfaceUI["panelMain"].y,this.interfaceUI["panelBuild"].y);
			if(_isHideMainPanel==value)return;
			//			if(this._isMoveBuildPanel || this._isMoveMainPanel)return;
			
			if(value){
				this._isMoveBuildPanel	= true;
				this._isMoveMainPanel	= true;
				//				TweenLite.to(this.interfaceUI["panelMain"],0.5,{y:this.interfaceUI["panelMain"].y+this.interfaceUI["panelMain"].height+_panelMainOffsetY,onComplete:setMovePanel("main",false)});
				//				TweenLite.to(this.interfaceUI["panelBuild"],0.5,{y:this.interfaceUI["panelBuild"].y+this.interfaceUI["panelBuild"].height+_panelBuildOffsetY,onComplete:setMovePanel("build",false)});
				
				this._interfaceUI["panelBuildInitY"]	=	this.parent.stage.stageHeight+this._panelBuildOffsetY;
				this._interfaceUI["panelMainInitY"]	=	this.parent.stage.stageHeight+this._panelMainOffsetY;
				
				if(	GV_Map.instance.buildMode==GV_Map.CANNOTBUILDMODE){
					TweenLite.to(this.interfaceUI["panelMain"],0.5,{y:this._interfaceUI["panelMainInitY"],onComplete:setMovePanel("main",false)});
					TweenLite.to(this.interfaceUI["panelBuild"],0.5,{y:this._interfaceUI["BPdefaultY"],onComplete:setMovePanel("build",false)});
				}
				else{
					TweenLite.to(this.interfaceUI["panelMain"],0.5,{y:this._interfaceUI["MPdefaultY"],onComplete:setMovePanel("main",false)});
					TweenLite.to(this.interfaceUI["panelBuild"],0.5,{y:this._interfaceUI["panelBuildInitY"],onComplete:setMovePanel("build",false)});
				}
				
			}
			else{
				this._isMoveBuildPanel	= true;
				this._isMoveMainPanel	= true;
				
				this._interfaceUI["panelBuildInitY"]	=	this.parent.stage.stageHeight;
				this._interfaceUI["panelMainInitY"]	=	this.parent.stage.stageHeight;
				
				if(GV_Map.instance.buildMode==GV_Map.CANNOTBUILDMODE)
					TweenLite.to(this.interfaceUI["panelMain"],0.5,{y:this._interfaceUI["panelMainInitY"],onComplete:setMovePanel("main",false)});
				else
					TweenLite.to(this.interfaceUI["panelBuild"],0.5,{y:this._interfaceUI["panelBuildInitY"],onComplete:setMovePanel("build",false)});
			}
			
			_isHideMainPanel		=	value;
		}
		public function get isHideMainPanel():Boolean
		{
			return _isHideMainPanel;
		}
		
		public function setMovePanel(panel:String,value:Boolean):void
		{
			
			if(panel=="main")this._isMoveMainPanel=value;
			if(panel=="build")this._isMoveBuildPanel=value;
			//			if(this._isHideMainPanel	==	this._isMoveBuildPanel)
			//				this.interfaceUI["hideSlideFastenerBtn"]["setNoMove"]();
			
		}
		
		public function clickCLSmallHandler(e:Event):void		//下拉
		{
			if(this.isHideMainPanel == true)return;
			this.interfaceUI["hideSlideFastenerBtn"]["setMove"]();
			this.isHideMainPanel	=	true;
		}
		
		public function clickCLBigHandler(e:Event):void		//上拉
		{
			if(this.isHideMainPanel == false)return;
			this.interfaceUI["hideSlideFastenerBtn"]["setMove"]();
			this.isHideMainPanel	=	false;
			
		}
		
		public function clickCL(e:Event):void
		{
			this.interfaceUI["hideSlideFastenerBtn"]["setMove"]();
			this.isHideMainPanel	=	!this.isHideMainPanel;
		}
		
		private function yqhyFun(e:Event):void
		{
			ExternalInterface.call("invite");
		}
	}
}